﻿using ConfExpert.Forms.Base;
using DevExpress.XtraEditors;
using DevTeam;

using System;
namespace ConfExpert.Forms.Depo.Cikis
{
    public partial class SatisFiyati : XForm
    {
        int SatisId;
        int CikisEmriId;
        public SatisFiyati(int CikisEmriId, int SatisId)    //SatisId, DEPO İÇİ SATIŞ için
        {
            InitializeComponent();
            this.CikisEmriId = CikisEmriId;
            this.SatisId = SatisId;
        }

        private void SatisFiyati_Load(object sender, EventArgs e)
        {
            
            gridView1.Init("GetCikisEmriSatis", CikisEmriId, SatisId);
            gridView1.MakeColumnInvisible("CikisEmriId", "SatisId");
            gridView1.FormatAsNumber(1, "Qty");
            gridView1.AddColumn("LineTotal", typeof(int), "Qty*Fiyat");
            gridView1.FormatAsNumber(2, "Fiyat", "LineTotal");
            gridView1.AddSummary("Fiyat", "LineTotal");
            gridView1.BestFitColumns();

            beiCurrency.Edit.Assign(RI(Rp.Currency));
            beiCurrency.EditValueChanged += beiCurrency_EditValueChanged;
            beiCurrency.EditValue = 1;

            bbiKaydet.ItemClick += bbiKaydet_ItemClick;
        }

        void beiCurrency_EditValueChanged(object sender, EventArgs e)
        {
            CurrencyId = beiCurrency.EditValue.ToInt();
        }

        int CurrencyId = 1;
        void bbiKaydet_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gridView1.EndEditing();

            if (gridView1.DataTable().Select("Fiyat is null").Length > 0)
                XtraMessageBox.Show("Bütün artikellerin fiyatını doldurmadan kaydedemezsiniz.");
            else
            {
                ExecuteNonQuery("UpdCikisEmriSatis", CikisEmriId, SatisId, CurrencyId, gridView1.SerializeChanges());

                //gridView1.Update("CikisEmriId,ProductId,Qty,Fiyat,CurrencyId", "CikisEmriSatis");
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
            }
        }
    }
}
